<template>
  <div class="left">
    <div class="left-top">
      <img class="Head" :src="Head" />
      <span class="Info" id="name1">{{ userName }}</span>
      <span class="Info" id="email1">{{ userEmail }}</span>
    </div>
    <div class="left-button">
      <ul class="Function">
        <li class="function" id="imageDetection" @click="toImage" tabindex="0">
          <img src="../msg/image.png" class="image" />图片检测
        </li>
        <li class="function" id="videoDetection" @click="toVideo" tabindex="0">
          <img src="../msg/video.png" class="image" />视频检测
        </li>
        <li class="function" id="classComment" @click="toCommend" tabindex="0">
          <img src="../msg/im2.png" class="image" />课堂评价
        </li>
        <li
          class="function"
          id="classManage"
          @click="toManageClass"
          tabindex="0"
        >
          <img src="../msg/icon-09.png" class="image" />课程管理
        </li>
      </ul>
      <img src="../msg/2.png" class="img" />
    </div>
  </div>
</template>
  
  <script>
export default {
  name: "Left",
  data() {
    return {
      Head: sessionStorage.getItem("Head"),
    };
  },
  mounted() {
    console.log("$router:", this.$router);
    if (this.$router.currentRoute.path === "/RulerMain") {
      this.changChick("#imageDetection");
    }
    if (this.$router.currentRoute.path === "/RulerMain/VideoDetection") {
      this.changChick("#videoDetection");
    }
    if (this.$router.currentRoute.path === "/RulerMain/Assessment") {
      this.changChick("#classComment");
    }
    if (this.$router.currentRoute.path === "/RulerMain/ClassManage") {
      this.changChick("#classManage");
    }
  },
  computed: {
    userEmail() {
      return sessionStorage.getItem("Email");
    },
    userName() {
      return sessionStorage.getItem("Name");
    },
  },
  methods: {
    changChick(target) {
      document.querySelectorAll(".function").forEach(function (el) {
        el.style.backgroundColor = "rgb(255, 255, 255)"; // Reset background color for all elements
      });

      document.querySelector(target).style.backgroundColor = "#f09ff0"; // Set background color for the selected element
    },
    toImage() {
      this.changChick("#imageDetection");
      if (this.$router.currentRoute.path !== "/RulerMain") {
        this.$router.replace({
          path: "/RulerMain",
        });
      }
    },
    toVideo() {
      this.changChick("#videoDetection");
      if (this.$router.currentRoute.path !== "/RulerMain/VideoDetection") {
        this.$router.replace({
          path: "/RulerMain/VideoDetection",
        });
      }
    },
    toCommend() {
      this.changChick("#classComment");
      if (this.$router.currentRoute.path !== "/RulerMain/Assessment") {
        this.$router.replace({
          path: "/RulerMain/Assessment",
        });
      }
    },
    toManageClass() {
      this.changChick("#classManage");
      if (this.$router.currentRoute.path !== "/RulerMain/ClassManage") {
        this.$router.replace({
          path: "/RulerMain/ClassManage",
        });
      }
    },
  },
};
</script>
  
<style scoped>
.img {
  position: relative;
  top: 100px;
  width: 200px;
}
.left-top {
  box-sizing: border-box;
  z-index: 1;
  bottom: 0;
  letter-spacing: 0;
  border-radius: 3px;
  margin: 6px;
  width: 200px;
  height: 26%;
  background-color: rgb(255, 255, 255);
  position: absolute;
  top: 10.9%;
  left: 84px;
  transform: translate(-44.5%, -45%);
}
.active {
  background-color: #eeb5eb; /* 你可以根据需要更改颜色 */
  color: #fff;
}
.left-button {
  box-sizing: border-box;
  z-index: 1;
  bottom: 0;
  letter-spacing: 0;
  border-radius: 3px;
  margin: 6px;
  width: 200px;
  height: 73%;
  background-color: rgb(255, 255, 255);
  position: absolute;
  top: 59%;
  left: 84px;
  transform: translate(-44.5%, -45%);
}
.Head {
  height: 50px;
  width: 50px;
  border-radius: 25px;
  background-color: #eeb5eb;
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.Info {
  color: rgb(47, 47, 47);
}

.Info[id="name1"] {
  position: absolute;
  top: 56%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-weight: 1000;
  font-size: 17px;
}

.Info[id="email1"] {
  color: rgb(74, 74, 74);
  position: absolute;
  top: 71%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-weight: 500;
  font-size: 13px;
}
.image {
  position: relative;
  width: 25px;
  height: 25px;
  left: -15px;
  top: 6px;
}
.Function {
  position: relative;
  top: 10px;
  padding: 8px 0;
  list-style-image: none;
  list-style-position: outside;
  list-style-type: none;
  margin: 0;
}
.function {
  margin-top: 30px;
  height: 35px;
  width: 180px;
  left: -2px;
  border-radius: 3px;
  color: #2e2f33;
  font-size: 16px;
  font-weight: 550;
  margin: 4px 12px 0;
  position: relative;
  display: list-item;
  text-align: -webkit-match-parent;
  text-align: center;
  list-style: none;
}
.function:hover {
  background-color: #efddef !important; /* 鼠标悬停时的颜色 */
}

.function:focus {
  background-color: #f09ff0;
}
</style>